﻿using Common;
using JQ50037.Procdure;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JQ50037.ViewModel
{
    internal class SetParamViewModel : NotifyBase
    {
        private int _goalTemp;

        public int GoalTemp
        {
            get { return _goalTemp; }
            set
            {
                _goalTemp = value;
                this.DoNotify();
            }
        }

        private double _minTemp;

        public double MinTemp
        {
            get { return _minTemp; }
            set
            {
                _minTemp = value;
                this.DoNotify();
            }
        }

        private double _maxTemp;

        public double MaxTemp
        {
            get { return _maxTemp; }
            set
            {
                _maxTemp = value;
                this.DoNotify();
            }
        }

        private double _liquidLevel;

        /// <summary>
        /// 液位
        /// </summary>
        public double LiquidLevel
        {
            get { return _liquidLevel; }
            set
            {
                _liquidLevel = value;
                this.DoNotify();
            }
        }

        private double _flowRateMin;

        public double FlowRateMin
        {
            get { return _flowRateMin; }
            set
            {
                _flowRateMin = value;
                this.DoNotify();
            }
        }

        private double _flowRateMax;

        public double FlowRateMax
        {
            get { return _flowRateMax; }
            set
            {
                _flowRateMax = value;
                this.DoNotify();
            }
        }

        private int _hours;

        public int Hours
        {
            get { return _hours; }
            set
            {
                _hours = value;
                this.DoNotify();
            }
        }

        private int _minutes;

        public int Minutes
        {
            get { return _minutes; }
            set
            {
                _minutes = value;
                this.DoNotify();
            }
        }

        public SetParamViewModel()
        {
            Config config = Config.Load();
            GoalTemp = config.GoalTemp;
            Hours = config.Hours;
            Minutes = config.Minutes;
            MaxTemp = config.TemperatureMax;
            MinTemp = config.TemperatureMin;
            LiquidLevel = config.LiquidLevelMin;
            FlowRateMax = config.FlowRateMax;
            FlowRateMin = config.FlowRateMin;

            SaveCommand = new CommandBase(Save);
            ResetTotalFlowCommand = new CommandBase(ResetTotalFlow);
        }

        private void ResetTotalFlow(object obj)
        {
            try
            {
            }
            catch (Exception ex)
            {
                Mylog.Error(ex, ex.Message);
            }
        }

        private void Save(object obj)
        {
            try
            {
                Config config = Config.Load();
                config.GoalTemp = GoalTemp;
                config.Hours = Hours;
                config.Minutes = Minutes;
                config.TemperatureMax = MaxTemp;
                config.TemperatureMin = MinTemp;
                config.LiquidLevelMin = LiquidLevel;
                config.FlowRateMax = FlowRateMax;
                config.FlowRateMin = FlowRateMin;
                Config.Save(config);
                
            }
            catch (Exception ex)
            {
                Mylog.Error(ex, ex.Message);
            }
        }

        public CommandBase SaveCommand { get; set; }
        public CommandBase ResetTotalFlowCommand { get; set; }
    }
}